import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:excel_utils/repository/k8/k8_repository.dart';

import '../../../../../daily/daily_report/bean/CustomerBean.dart';


part 'week_data_entry_state.dart';

class WeekDataEntryCubit extends Cubit<WeekDataEntryState> {

  K8Repository _k8Repository;

  WeekDataEntryCubit(this._k8Repository) : super(WeekDataEntryInitial());


  refresh(){
    emit(WeekDataEntryRefreshingState(timeStamp: DateTime.now().millisecondsSinceEpoch));
  }
  
  search({required List<String> customerNo}) async {
    
    emit(WeekDataEntryCustomerSearchLoadingState());

    List<Future<CustomerBean>> futures = [];
    for (var value in customerNo) {
      futures.add(_k8Repository.queryCustomerData(maps: {'cmCode': value}));
    }
    List<CustomerBean> customerData =  await Future.wait(futures);

    emit(WeekDataEntryCustomerSearchSuccessState(customerData: customerData));

  }
  
}
